<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Set collation strength</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="collator.setattribute.html">« Collator::setAttribute</a></li>
      <li style="float: right;"><a href="collator.sortwithsortkeys.html">Collator::sortWithSortKeys »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.collator.html">Collator</a></li>
    <li>Set collation strength</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="collator.setstrength" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Collator::setStrength</h1>
  <h1 class="refname">collator_set_strength</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.3.0, PHP 7, PHP 8, PECL intl &gt;= 1.0.0)</p><p class="refpurpose"><span class="refname">Collator::setStrength</span> -- <span class="refname">collator_set_strength</span> &mdash; <span class="dc-title">Set collation strength</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-collator.setstrength-description">
  <h3 class="title">说明</h3>
  <p class="para">
   面向对象风格
  </p>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>Collator::setStrength</strong></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$strength</code></span>): <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   过程化风格
  </p>
  <div class="methodsynopsis dc-description"><span class="methodname"><strong>collator_set_strength</strong></span>(<span class="methodparam"><span class="type"><a href="class.collator.html" class="type Collator">Collator</a></span> <code class="parameter">$object</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$strength</code></span>): <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   The
   <a href="http://www.icu-project.org/" class="link external">&raquo;&nbsp;ICU</a>
   Collation Service supports many levels of comparison (named &quot;Levels&quot;, but
   also known as &quot;Strengths&quot;). Having these categories enables ICU to sort
   strings precisely according to local conventions. However, by allowing the
   levels to be selectively employed, searching for a string in text can be
   performed with various matching conditions.
  </p>
  <p class="para">
   <ol type="1">
    <li class="listitem">
     <p class="para"> 
      <em class="emphasis">Primary Level</em>:
      Typically, this is used to denote differences between base characters
      (for example, &quot;a&quot; &lt; &quot;b&quot;). It is the strongest difference. For
      example, dictionaries are divided into different sections by base
      character. This is also called the <code class="literal">level 1</code> strength.
     </p>
    </li>
    <li class="listitem">
     <p class="para"> 
      <em class="emphasis">Secondary Level</em>:
      Accents in the characters are considered secondary differences (for
      example, &quot;as&quot; &lt; &quot;às&quot; &lt; &quot;at&quot;). Other differences between letters
      can also be considered secondary differences, depending on the language.
      A secondary difference is ignored when there is a primary difference
      anywhere in the strings. This is also called the <code class="literal">level 2</code> strength.
      <blockquote class="note"><p><strong class="note">注意</strong>: 
       <p class="para">
        Note: In some languages (such as Danish), certain accented letters are
        considered to be separate base characters. In most languages, however,
        an accented letter only has a secondary difference from the unaccented
        version of that letter.
       </p>
      </p></blockquote>
     </p>
    </li>
    <li class="listitem">
     <p class="para"> 
      <em class="emphasis">Tertiary Level</em>:
      Upper and lower case differences in characters are distinguished at
      the tertiary level (for example, &quot;ao&quot; &lt; &quot;Ao&quot; &lt; &quot;aò&quot;). In addition,
      a variant of a letter differs from the base form on the tertiary level
      (such as &quot;A&quot; and &quot; &quot;). Another example is the difference between large
      and small Kana. A tertiary difference is ignored when there is a primary
      or secondary difference anywhere in the strings. This is also called the
      <code class="literal">level 3</code> strength.
     </p>
    </li>
    <li class="listitem">
     <p class="para"> 
      <em class="emphasis">Quaternary Level</em>:
      When punctuation is ignored (see Ignoring Punctuations ) at levels 1-3,
      an additional level can be used to distinguish words with and without
      punctuation (for example, &quot;ab&quot; &lt; &quot;a-b&quot; &lt; &quot;aB&quot;). This difference is
      ignored when there is a primary, secondary or tertiary difference. This
      is also known as the <code class="literal">level 4</code> strength. The quaternary level should only
      be used if ignoring punctuation is required or when processing Japanese
      text (see Hiragana processing).
     </p>
    </li>
    <li class="listitem">
     <p class="para"> 
      <em class="emphasis">Identical Level</em>:
      When all other levels are equal, the identical level is used as a
      tiebreaker. The Unicode code point values of the NFD form of each string
      are compared at this level, just in case there is no difference at
      levels 1-4. For example, Hebrew cantillation marks are only distinguished
      at this level. This level should be used sparingly, as only code point
      values differences between two strings is an extremely rare occurrence.
      Using this level substantially decreases the performance for both
      incremental comparison and sort key generation (as well as increasing
      the sort key length). It is also known as <code class="literal">level 5</code> strength.
     </p>
    </li>
   </ol>
  </p>
  <p class="para">
   For example, people may choose to ignore accents or ignore accents and case
   when searching for text. Almost all characters are distinguished by the
   first three levels, and in most locales the default value is thus Tertiary.
   However, if Alternate is set to be Shifted, then the Quaternary strength
   can be used to break ties among whitespace, punctuation, and symbols that
   would otherwise be ignored. If very fine distinctions among characters are
   required, then the Identical strength can be used (for example, Identical
   Strength distinguishes between the Mathematical Bold Small A and the
   Mathematical Italic Small A.). However, using levels higher than Tertiary
   the Identical strength result in significantly longer sort keys, and slower
   string comparison performance for equal strings.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-collator.setstrength-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">object</code></dt>

     <dd>

      <p class="para">
       <span class="classname"><a href="class.collator.html" class="classname">Collator</a></span> object.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">strength</code></dt>

     <dd>

      <p class="para">Strength to set.</p>
      <p class="para">
       Possible values are:
       <ul class="itemizedlist">
        <li class="listitem">
         <p class="para">
          <strong><code>Collator::PRIMARY</code></strong>
         </p>
        </li>
        <li class="listitem">
         <p class="para">
          <strong><code>Collator::SECONDARY</code></strong>
         </p>
        </li>
        <li class="listitem">
         <p class="para">
          <strong><code>Collator::TERTIARY</code></strong>
         </p>
        </li>
        <li class="listitem">
         <p class="para">
          <strong><code>Collator::QUATERNARY</code></strong>
         </p>
        </li>
        <li class="listitem">
         <p class="para">
          <strong><code>Collator::IDENTICAL</code></strong>
         </p>
        </li>
        <li class="listitem">
         <p class="para">
          <strong><code>Collator::DEFAULT_STRENGTH</code></strong>
         </p>
        </li>
       </ul>
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-collator.setstrength-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>true</code></strong>， 或者在失败时返回 <strong><code>false</code></strong>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-collator.setstrength-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-2293">
    <p><strong>示例 #1 <span class="function"><strong>collator_set_strength()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$arr&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;array(&nbsp;</span><span style="color: #DD0000">'aò'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'Ao'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'ao'&nbsp;</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$coll&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">collator_create</span><span style="color: #007700">(&nbsp;</span><span style="color: #DD0000">'en_US'&nbsp;</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Sort&nbsp;array&nbsp;using&nbsp;default&nbsp;strength.<br /></span><span style="color: #0000BB">collator_sort</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$coll</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$arr&nbsp;</span><span style="color: #007700">);&nbsp;<br /></span><span style="color: #0000BB">var_export</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$arr&nbsp;</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Sort&nbsp;array&nbsp;using&nbsp;primary&nbsp;strength.<br /></span><span style="color: #0000BB">collator_set_strength</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$coll</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">Collator</span><span style="color: #007700">::</span><span style="color: #0000BB">PRIMARY&nbsp;</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">collator_sort</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$coll</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$arr&nbsp;</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">var_export</span><span style="color: #007700">(&nbsp;</span><span style="color: #0000BB">$arr&nbsp;</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
array (
  0 =&gt; &#039;ao&#039;,
  1 =&gt; &#039;Ao&#039;,
  2 =&gt; &#039;aò&#039;,
)
array (
  0 =&gt; &#039;aò&#039;,
  1 =&gt; &#039;Ao&#039;,
  2 =&gt; &#039;ao&#039;,
)
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-collator.setstrength-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><a href="class.collator.html#intl.collator-constants" class="link"><span class="classname"><a href="class.collator.html" class="classname">Collator</a></span> constants</a></li>
    <li class="member"><span class="function"><a href="collator.getstrength.html" class="function" rel="rdfs-seeAlso">collator_get_strength()</a> - Get current collation strength</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>